package cn.edu.scau.dormitory_management_system.service.impl;

import cn.edu.scau.dormitory_management_system.dao.StudentDao;
import cn.edu.scau.dormitory_management_system.entity.BedEntity;
import cn.edu.scau.dormitory_management_system.entity.DormEntity;
import cn.edu.scau.dormitory_management_system.entity.DormbuildEntity;
import cn.edu.scau.dormitory_management_system.entity.StudentEntity;
import cn.edu.scau.dormitory_management_system.service.BedService;
import cn.edu.scau.dormitory_management_system.service.DormService;
import cn.edu.scau.dormitory_management_system.service.DormbuildService;
import cn.edu.scau.dormitory_management_system.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;



@Service("studentService")
public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> implements StudentService {

    @Autowired
    private StudentService studentService;

    @Autowired
    private BedService bedService;

    @Autowired
    private DormService dormService;

    @Autowired
    private DormbuildService dormbuildService;

    @Override
    public DormEntity getDorm(String Id){
        QueryWrapper bedWrapper = new QueryWrapper<BedEntity>();
        bedWrapper.eq("stu_id",Id);
        BedEntity bedEntity = bedService.getOne(bedWrapper);
        if(bedEntity == null) return  null;

        QueryWrapper dormWrapper = new QueryWrapper<DormEntity>();
        dormWrapper.eq("dorm_id",bedEntity.getDormId());
        DormEntity dormEntity = dormService.getOne(dormWrapper);

        return dormEntity;
    }

    @Override
    public DormbuildEntity getBuild(String Id){
        QueryWrapper bedWrapper = new QueryWrapper<BedEntity>();
        bedWrapper.eq("stu_id",Id);
        BedEntity bedEntity = bedService.getOne(bedWrapper);
        if(bedEntity == null) return  null;

        QueryWrapper dormWrapper = new QueryWrapper<DormEntity>();
        dormWrapper.eq("dorm_id",bedEntity.getDormId());
        DormEntity dormEntity = dormService.getOne(dormWrapper);
        if(dormEntity == null) return  null;

        QueryWrapper buildWrapper = new QueryWrapper<DormEntity>();
        buildWrapper.eq("build_id",dormEntity.getBuildId());
        DormbuildEntity dormbuildEntity = dormbuildService.getOne(buildWrapper);

        return  dormbuildEntity;
    }
}